<h2>DESCRIPTION</h2>

<em>db.select</em> prints result of selection from database based on
SQL statement read from input file or from standard input to standard
output. Each individual query has to be written on one single line and 
different queries have to be written on separate lines.

<h2>NOTE</h2>

If parameters for database connection are already set with
<em><a href="db.connect.html">db.connect</a></em>, they are taken as
default values and do not need to be specified each time. Output will
be displayed to standard output or can be directed to a file
(option <b>output</b>).

<h2>EXAMPLES</h2>

<h3>Basic usage</h3>
<div class="code"><pre>
db.select sql="select * from roads"
</pre></div>
or
<div class="code"><pre>
echo "select * from roads" | db.select input=-
</pre></div>
or
<div class="code"><pre>
db.select input=file.sql
</pre></div>
or
<div class="code"><pre>
cat file.sql | db.select input=-
</pre></div>

<p>
Select all from table roads:
<div class="code"><pre>
db.select -c driver=odbc database=mydb table=hospitals \
          input=file.sql output=result.csv
</pre></div>

<p>
Select some string attribute, exclude others:
<div class="code"><pre>
db.select sql="SELECT * FROM archsites WHERE str1 &lt;&gt; 'No Name'"
</pre></div>

<p>
Select some string attribute with ZERO length:
<div class="code"><pre>
db.select sql="SELECT * FROM archsites WHERE str1 IS NULL"
</pre></div>

<p>
Select coordinates from PostGIS table:
<div class="code"><pre>
db.select sql="SELECT x(geo),y(geo) FROM localizzazione"
</pre></div>

<h3>Execute multiple SQL statements</h3>

<div class="code"><pre>
cat file.sql
SELECT * FROM busstopsall WHERE cat = 1
SELECT cat FROM busstopsall WHERE cat > 4 AND cat &lt; 8

db.select input=file.sql
</pre></div>

<p>

<h3>Count number of cases falling into same position</h3>

When multiple observation have the spatial coordinates, they can still
be counted (if needed, coordinates can be uploaded to the attribute
table by <em>v.to.db</em>:

<div class="code"><pre> 
db.select sql="SELECT long,lat,site_id,department,obs,COUNT(long) as count_cases \
               FROM diseases GROUP BY long,lat"
</pre></div>

<h2>SEE ALSO</h2>

<em>
<a href="db.connect.html">db.connect</a>,
<a href="db.describe.html">db.describe</a>,
<a href="db.drivers.html">db.drivers</a>,
<a href="db.droptable.html">db.droptable</a>,
<a href="db.execute.html">db.execute</a>,
<a href="db.login.html">db.login</a>,
<a href="db.tables.html">db.tables</a>
</em>
<p>
<em>
<a href="sql.html">GRASS SQL interface</a>
</em>

<h2>AUTHORS</h2>

Original author unknown (probably CERL)<br>
Modifications by Radim Blazek, ITC-Irst, Trento, Italy<br>
Support for multiple statements by Martin Landa, Czech Technical University in Prague

<!--
<p>
<i>Last changed: $Date$</i>
-->
